--- title: Blurry keywords: fastai sidebar: home_sidebar summary: "**Blurry** detects faces in photos and blurs them to increase privacy." description: "**Blurry** detects faces in photos and blurs them to increase privacy." nb_path: "00_core.ipynb" ---
Helper function to show cv2 images in Jupyter notebook
Simple Gaussian blur
Testing blur:
test_img = cv2.imread('test_images/small.jpg')
assert test_img.shape == blur(test_img).shape, "Function should not change shape of array"
assert test_img.shape == blur(test_img, factor=0.5).shape, "Factors < 1 should work"
tiny = np.zeros((5,5,3), dtype = np.uint8)
assert tiny.shape == blur(tiny, factor=10).shape, "Blur function should work also when kernel size > image size"
show_cv2(test_img)
show_cv2(blur(test_img))
Test pixelate:
assert test_img.shape == pixelate(test_img).shape, "Function should not change shape of array"
assert len(np.unique(test_img)) > len(np.unique(pixelate(test_img))), "Number of unique colors should have been reduced"
assert len(np.unique(pixelate(test_img, factor=0.5))) > len(np.unique(pixelate(test_img, factor=5))), "Large factor should reduce number of unique colors"
tiny = np.zeros((5,5,3), dtype = np.uint8)
assert tiny.shape == pixelate(tiny).shape, "Pixelate function should also work on tiny images"
show_cv2(pixelate(test_img))
group_img = cv2.imread('test_images/group.jpg')
faces = find_faces(group_img)
assert len(faces) == 7, "there should be 7 faces in the group test image"
Does it work?
img = group_img.copy()
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
show_cv2(img)
img = load_img('test_images/group_closer.jpg')
show_cv2(anonymize(img, factor=1, mode='pixelate'))
img = load_img('test_images/group_closer.jpg')
show_cv2(anonymize(img, factor=1))
test_bulk('test_images', factor=1)